<?php 
	defined('IN_ADMIN') or exit('No permission resources.');
	include $this->admin_tpl('header', 'admin');
?>
<script type="text/javascript" src="<?php echo JS_PATH?>jquery-3.5.1.min.js"></script>
<link rel="stylesheet" href="<?php echo CSS_PATH;?>bootstrap/css/bootstrap.min.css" media="all" />
<script type="text/javascript" src="<?php echo CSS_PATH?>bootstrap/js/bootstrap.min.js"></script>
<link rel="stylesheet" href="<?php echo JS_PATH;?>layui/css/layui.css" media="all" />
<link rel="stylesheet" href="<?php echo CSS_PATH;?>admin/css/global.css" media="all" />
<style type="text/css">
.btn-group {margin-left: 10px;}
.input-text, .measure-input, textarea, input.date, input.endDate, .input-focus {height: 32px;}
</style>
<div class="pad-lr-10">
<div class="admin-main layui-anim layui-anim-upbit">
  <!--<fieldset class="layui-elem-field layui-field-title">
    <legend><?php echo L('attachment_management');?></legend></fieldset>-->
  <blockquote class="layui-elem-quote">
<a class="layui-btn layui-btn-normal layui-btn-sm" href="javascript:;" onclick="javascript:$('#searchid').css('display','');"><?php echo L('search');?></a> 
</blockquote>
<div id="searchid" style="display:<?php if(!isset($_GET['search'])) echo 'none';?>">
<form name="searchform" action="" method="get" >
<input type="hidden" value="attachment" name="m">
<input type="hidden" value="manage" name="c">
<input type="hidden" value="init" name="a">
<input type="hidden" value="1" name="search">
<table width="100%" cellspacing="0" class="search-form">
    <tbody>
		<tr>
		<td><div class="explain-col"><?php echo L('name')?>  <input type="text" value="<?php echo $filename?>" class="input-text" name="info[filename]">  <?php echo L('uploadtime')?>  <?php echo form::date('info[start_uploadtime]',$start_uploadtime,'1','0','true','1')?><?php echo L('to')?>   <?php echo form::date('info[end_uploadtime]',$end_uploadtime)?>  <?php echo L('filetype')?>  <input type="text" value="<?php echo $fileext?>" class="input-text" name="info[fileext]">  <input type="submit" value="<?php echo L('search')?>" class="button" name="dosubmit"> <a href="?m=attachment&c=manage&a=dir&menuid=<?php echo $_GET['menuid']?>"><?php echo L('dir_schema')?></a>
		</div>
		</td>
		</tr>
    </tbody>
</table>
</form>
</div>
<div class="table-list table-checkable">
    <table class="layui-table" lay-filter="list">
        <thead>
		<tr>
        <th lay-data="{type:'checkbox', width:50, fixed: 'left'}"></th>
		<th lay-data="{field:'aid', width:80, sort: true}">ID</th>
		<th lay-data="{field:'moudle', width:120, sort: true}"><?php echo L('moudle')?></th>
		<th lay-data="{field:'catname', width:120, sort: true}"><?php echo L('catname')?></th>
		<th lay-data="{field:'filename', minWidth:340, sort: true, edit: 'text'}"><?php echo L('filename')?></th>
		<th lay-data="{field:'fileext', width:120, sort: true}"><?php echo L('fileext')?></th>
		<th lay-data="{field:'filesize', width:120, sort: true}"><?php echo L('filesize')?></th>
		<th lay-data="{field:'uploadtime', width:180, sort: true}"><?php echo L('uploadtime')?></th>
		<th lay-data="{field:'operations_manage', width:120, align: 'center', fixed: 'right'}"><?php echo L('operations_manage')?></th>
		</tr>
        </thead>
        
    <tbody>
<?php 
if(is_array($infos)){
	foreach($infos as $info){
		$thumb = glob(dirname($this->upload_path.$info['filepath']).'/thumb_*'.basename($info['filepath']));
?>
<tr>
<td></td>
<td align="center"><?php echo $info['aid']?></td>
<td align="center"><?php echo $modules[$info['module']]['name']?></td>
<td align="center"><?php echo $category[$info['catid']]['catname']?></td>
<td><?php echo $info['filename']?></td>
<td align="center"><?php echo $info['fileext']?><img src="<?php echo file_icon('.'.$info['fileext'],'gif')?>" /><?php echo $thumb ? '<img title="'.L('att_thumb_manage').'" src="statics/images/admin_img/havthumb.png" onclick="showthumb('.$info['aid'].', \''.new_addslashes($info['filename']).'\')"/>':''?> <?php echo $info['status'] ? '<img src="statics/images/admin_img/link.png"':''?></td>
<td align="center"><?php echo $this->attachment->size($info['filesize'])?></td>
<td align="center"><?php echo date('Y-m-d H:i:s',$info['uploadtime'])?></td>
<td align="center"><a href="javascript:preview(<?php echo $info['aid']?>, '<?php echo $info['filename']?>','<?php echo $this->upload_url.$info['filepath']?>')" class="layui-btn layui-btn-xs layui-btn-normal"><?php echo L('preview')?></a><a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="delete"><?php echo L('delete')?></a></td>
</tr>
<?php 
	}
}
?>
</tbody>
</table>
<div id="pages"> <?php echo $pages?></div>
</div>
</div>
</div>
<script type="text/javascript" src="<?php echo JS_PATH;?>layui/layui.js"></script>
<script type="text/html" id="topBtn">
    <button type="button" class="layui-btn layui-btn-danger layui-btn-sm" id="delAll"><?php echo L('thorough');?><?php echo L('delete');?></button>
    <div class="btn-group">
        <button type="button" class="layui-btn layui-btn-sm layui-btn-normal" id="dropdown" data-toggle="dropdown"><i class="fa fa-files-o"></i> <?php echo L('moudle')?></button>
        <div class="dropdown dropdown-bottom-left">
            <?php foreach ($modules as $module) {
            if(in_array($module['module'], array('pay','digg','search','scan','attachment','block','dbsource','template','release','cnzz','comment','mood'))) continue;
            if ($i) echo '<div class="dropdown-line"></div>';
            echo '<a href='.url_par('dosubmit=1&module='.$module['module']).' class="dropdown-item" id="link"><i class="fa fa-chain"></i> '.$module['name'].'</a>';
            $i++;
            }?>
        </div>
    </div>
    <div class="btn-group">
        <button type="button" class="layui-btn layui-btn-sm layui-btn-normal" id="dropdown" data-toggle="dropdown"><i class="fa fa-files-o"></i> <?php echo L('filename')?></button>
        <div class="dropdown dropdown-bottom-left">
            <a href="<?php echo url_par('dosubmit=1&status=0')?>" class="dropdown-item"><i class="fa fa-chain"></i> <?php echo L('not_used');?></a>
            <div class="dropdown-line"></div>
            <a href="<?php echo url_par('dosubmit=1&status=1')?>" class="dropdown-item"><i class="fa fa-chain"></i> <?php echo L('used');?></a>
        </div>
    </div>
</script>
<script>
layui.use(['table','form'], function(){
    var table = layui.table, form = layui.form;
    //转换静态表格
    table.init('list', {
        id: 'content',
        toolbar: '#topBtn',
        //height: 450,
        limit: <?php echo $pagesize.PHP_EOL;?>
    });
    //监听单元格编辑
    table.on('edit(list)',function(obj) {
        var value = obj.value, data = obj.data, field = obj.field;
        if (field=='filename' && value=='') {
            layer.tips('<?php echo L('attachment_name_not')?>',this,{tips: [1, '#000']});
            return false;
        }else{
            $.ajax({
                type: 'post',
                url: '?m=attachment&c=manage&a=update&dosubmit=1&pc_hash='+pc_hash,
                data: {aid:data.aid,field:field,value:value},
                dataType: 'json',
                success: function(res) {
                    if (res.code == 1) {
                        layer.msg(res.msg, {time: 1000, icon: 1}, function () {
                            location.reload();
                        });
                    }else{
                        layer.msg(res.msg,{time:1000,icon:2});
                    }
                }
            });
        }
    });
    table.on('tool(list)', function(obj) {
        var data = obj.data;
        if(obj.event === 'delete'){
            layer.confirm('<?php echo L('del_confirm')?>', {icon: 3}, function(index){
                layer.close(index);
                var loading = layer.load(1, {shade: [0.1, '#fff']});
                $.ajax({
                    type: 'post',
                    url: '?m=attachment&c=manage&a=delete&pc_hash='+pc_hash,
                    data: {aid:data.aid},
                    dataType: 'json',
                    success: function(res) {
                        layer.close(loading);
                        if (res.code==1) {
                            layer.msg(res.msg,{time:1000,icon:1});
                            obj.del();
                        }else{
                            layer.msg(res.msg,{time:1000,icon:2});
                        }
                    }
                });
            });
        }
    });
    $('body').on('click','#delAll',function() {
        var checkStatus = table.checkStatus('content'); //content即为参数id设定的值
        var ids = [];
        $(checkStatus.data).each(function (i, o) {
            ids.push(o.aid);
        });
        if (ids.toString()=='') {
            layer.msg('\u81f3\u5c11\u9009\u62e9\u4e00\u6761\u4fe1\u606f',{time:1000,icon:2});
        } else {
            layer.confirm('<?php echo L('del_confirm')?>', {icon: 3}, function(index) {
                layer.close(index);
                var loading = layer.load(1, {shade: [0.1, '#fff']});
                $.ajax({
                    type: 'post',
                    url: '?m=attachment&c=manage&a=public_delete_all',
                    data: {ids: ids},
                    dataType: 'json',
                    success: function(res) {
                        layer.close(loading);
                        if (res.code==1) {
                            layer.msg(res.msg,{icon: 1, time: 1000},function(){
                                location.reload();
                            });
                        }else{
                            layer.msg(res.msg,{time:1000,icon:2});
                        }
                    }
                });
            });
        }
    })
});
</script>
</body>
</html>
<script type="text/javascript">
<!--
window.top.$('#display_center_id').css('display','none');
function preview(id, name,filepath) {
	if(IsImg(filepath)) {
		var diag = new Dialog({
			title:'<?php echo L('preview')?>',
			html:'<img src="'+filepath+'" onload="$(this).LoadImage(true, 500, 500,\'<?php echo IMG_PATH?>s_nopic.gif\');"/>',
			modal:true,
			autoClose:5
		});
		diag.show();
	} else if(IsMp4(filepath)) {
		var diag = new Dialog({
			title:'<?php echo L('preview')?>',
			html:'<video controls="true" src="'+filepath+'" width="420" height="238"></video>',
			modal:true
		});
		diag.show();
	} else if(IsMp3(filepath)) {
		var diag = new Dialog({
			title:'<?php echo L('preview')?>',
			html:'<audio src="'+filepath+'" controls="controls"></audio>',
			modal:true
		});
		diag.show();
	} else {
		var diag = new Dialog({
			title:'<?php echo L('preview')?>',
			html:'<a href="'+filepath+'" target="_blank"><img src="<?php echo IMG_PATH?>admin_img/down.gif"><?php echo L('click_open')?></a>',
			modal:true
		});
		diag.show();
	}
}

function att_delete(obj,aid){
	Dialog.confirm('<?php echo L('del_confirm')?>', function(){$.get('?m=attachment&c=manage&a=delete&aid='+aid+'&pc_hash='+pc_hash,function(data){if(data == 1) location.reload();})});
}

function showthumb(id, name) {
	var diag = new Dialog({
		id:'edit',
		title:'<?php echo L('att_thumb_manage')?>--'+name,
		url:'<?php echo SELF;?>?m=attachment&c=manage&a=pullic_showthumbs&aid='+id+'&pc_hash='+pc_hash,
		width:500,
		height:400,
		modal:true
	});
	diag.show();
}
function hoverUse(target){
	if($("#"+target).css("display") == "none"){
		$("#"+target).show();
	}else{
		$("#"+target).hide();
	}
}
function IsImg(url){
	  var sTemp;
	  var b=false;
	  var opt="jpg|gif|png|bmp|jpeg";
	  var s=opt.toUpperCase().split("|");
	  for (var i=0;i<s.length ;i++ ){
	    sTemp=url.substr(url.length-s[i].length-1);
	    sTemp=sTemp.toUpperCase();
	    s[i]="."+s[i];
	    if (s[i]==sTemp){
	      b=true;
	      break;
	    }
	  }
	  return b;
}
function IsMp4(url){
	  var sTemp;
	  var b=false;
	  var opt="mp4";
	  var s=opt.toUpperCase().split("|");
	  for (var i=0;i<s.length ;i++ ){
	    sTemp=url.substr(url.length-s[i].length-1);
	    sTemp=sTemp.toUpperCase();
	    s[i]="."+s[i];
	    if (s[i]==sTemp){
	      b=true;
	      break;
	    }
	  }
	  return b;
}
function IsMp3(url){
	  var sTemp;
	  var b=false;
	  var opt="mp3";
	  var s=opt.toUpperCase().split("|");
	  for (var i=0;i<s.length ;i++ ){
	    sTemp=url.substr(url.length-s[i].length-1);
	    sTemp=sTemp.toUpperCase();
	    s[i]="."+s[i];
	    if (s[i]==sTemp){
	      b=true;
	      break;
	    }
	  }
	  return b;
}
//-->
</script>